<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>我的微博</title>
</head>
<body>
<h1>我的微博</h1>
<div>
    <div v-for="weibo in arr">
        <h3>{{weibo.content}}</h3>
        <p>发布于:{{weibo.created}} <a href="javascript:void(0)" @click="del(weibo.id)">删除</a></p>
    </div>
</div>
<!--引入vue和axios-->
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!--引入moment.js-->
<script src="http://cdn.staticfile.org/moment.js/2.24.0/moment.min.js"></script>
<script>
    let v = new Vue({
        el:"body>div",
        data:{arr:[]},
        created:function () {
            //发请求获得当前登录用户发布的所有微博
            axios.get("/weibo/selectMyself").then(function (response) {
                v.arr=response.data;
                //遍历微博数组
                for (let weibo of v.arr){
                    //修改时间格式
                    weibo.created = moment(weibo.created).format("YYYY年MM月DD日 HH:mm:ss");
                }
            })
        },
        methods:{
            del:function (id) {
                if (confirm("您确认删除吗?")){
                    //发请求登出
                    axios.get("/weibo/delete?id="+id).then(function () {
                        location.reload();//刷新页面
                    })
                }
            }
        }
    })
</script>
</body>
</html>